<?php
class Menus_model extends Model
{
	const DEFAULT_CATEGORY = 'console';
	
	public function __construct()
	{
		
	}
	
	public function getMenuData($category = null)
	{
		$menuData = array();
		
		if(is_null($category))
		{
			if(isset($_COOKIE['menuCategory']))
				$category = $_COOKIE['menuCategory'];
			else				
				$category = self::DEFAULT_CATEGORY;
		}
		
		$menuData['category'] = $category;
		
		//table name
		switch ($category) 
		{
			case 'console':
				$this->tableName = 'consoles';
				break;
			case 'genre':
				$this->tableName = 'genres';
				break;
			default:
				$this->tableName = 'consoles';
		}
		
		
		// Build up the SQL query string and run the query
		$sql = 'SELECT * FROM  ' . $this->tableName ;
		$query = $this->db->query($sql);

		if ($query->num_rows() > 0) 
		{
			foreach ($query->result_array() as $row)      // Go through the result set
			{
				// Build up a list for each column from the database and place it in
				// ...the result set
				$query_results['id']		 = $row['id'];
				$query_results['name']		 = $row['name'];
				$menuData['menusList'][]		 = $query_results;
			}
		}
		return $menuData;
	}
	
}

?>